#!/bin/bash
# File Name   : mongo_full_backup.sh
# Author      : moshan
# Mail        : mo_shan@yeah.net
# Created Time: 2019-08-23 14:39:02
# Function    : 
#########################################################################
mongo_path="/data/mongodb/base/bin"
backup_path="/opt/backup"
nowtime="$(date "+%Y%m%d")"
backup_dir="${backup_path}/${nowtime}"
mongo_backup_port="27017"
mongo_backup_user="root"
mongo_backup_pass="123456"
mongo_backup_host="127.0.0.1"
preject_name="yyfq"

function f_start_full_backup()
{
	${mongo_path}/mongodump --host ${mongo_backup_host} --port ${mongo_backup_port} -u ${mongo_backup_user} -p "${mongo_backup_pass}" --oplog --gzip --authenticationDatabase "admin" --out ${backup_dir}
}

function f_execute_backup()
{
	echo "=======================${mongo_backup_port} ${preject_name} mongodb backup start $(date "+%F %H:%M:%S")========="
	f_start_full_backup
	if [ $? -eq 0 ]
	then
		echo "The MongoDB BackUp Successfully!"
	else 
		echo "The MongoDB BackUp Failure"
	fi
}

if [ ! -d "${backup_dir}" ]
then
  mkdir -p ${backup_dir}
fi
f_execute_backup

baktime=$(date -d '-3 days' "+%Y%m%d")
if [ -d "${targetpath}/${baktime}/" ]
then
	rm -rf "${targetpath}/${baktime}/"
	echo "=======${targetpath}/${baktime}/===删除完毕=="
fi
echo "=======================${mongo_backup_port} ${preject_name} mongodb backup end $(date "+%F %H:%M:%S")========="
